import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: liangyuanzhang
 * Date: 2025-3-15
 * Time: 16:23
 */
public class CarDemo {

    public static final String[] suits = {"♥","♠","♣","♦"};

    public List<Card> buyCard(){
        List<Card> cardList = new ArrayList<>();
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < 4; j++) {
                int rank = i;
                String suit = suits[j];
                Card card = new Card(suit,rank);
                cardList.add(card);
            }
        }
        return cardList;
    }

    public void shuffle(List<Card> cardList){
        Random random = new Random();

        for (int i = cardList.size()-1; i > 0 ; i--) {
            int index = random.nextInt(i);
            swap(cardList,i,index);
        }
    }

    public void swap(List<Card> cardList,int i,int j){
        /*
        不是数组 做不到
        Card tmp = cardList[i];
        cardList[i] = cardList[j];
        cardList[j] = tmp;
         */
        Card tmp = cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,tmp);
    }

    public List<List<Card>> play(List<Card> cardList){
        List<Card> head0 = new ArrayList<>();
        List<Card> head1 = new ArrayList<>();
        List<Card> head2 = new ArrayList<>();

        List<List<Card>> head = new ArrayList<>();
        head.add(head0);
        head.add(head1);
        head.add(head2);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cardList.remove(0);
                //怎么把对应的牌放到对应的人手里面
                head.get(j).add(card);
            }
        }
        return head;
    }

}
